<template>
  <div class="app-container user">
    <!-- <span @click="logout">个人中心</span> -->
    <van-nav-bar title="我的" left-arrow @click-left="$router.push('/home')" />
    <div class="content">
      <el-scrollbar>
        <div class="user-box">
          <div class="avatar">{{ nickname }}</div>
          <!-- <img class="avatar" :src="avatar"> -->
          <div class="user-info">
            <div class="user-name">{{ nickname }}</div>
            <div class="user-depart">{{ deptName }}</div>
          </div>
          <div class="handle-box">
            <el-button size="small" round @click="logout">退出</el-button>
          </div>
        </div>
        <div class="menu-box" v-for="menu in menuList" :key="menu.title">
          <div class="menu-title">{{ menu.title }}</div>
          <div class="content-box">
            <div class="menu-item" v-for="item in menu.itemList" :key="item.label" @click="$router.push(item.path)">
              <svg-icon :icon-class="item.icon" />
              <div class="label">{{ item.label }}</div>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <IndexTabBar />
  </div>
</template>

<script>
import IndexTabBar from '@/components/IndexTabBar/index.vue';
import { mapGetters } from 'vuex';

export default {
  name: 'UserView',
  components: { IndexTabBar },
  data() {
    return {
      menuList: [
        {
          title: '心灵驿站',
          itemList: [
            { label: '测评记录', icon: 'wallet', path: '/user/examTestRecord' },
            { label: '视频记录', icon: 'record' },
            { label: '训练记录', icon: 'shopping-bag' },
          ],
        },
        {
          title: '活动',
          itemList: [
            { label: '我的礼品', icon: 'gift', path: '/user/activity?title=我的礼品' },
            { label: '我的报名', icon: 'form', path: '/user/activity?title=我的报名' },
            // { label: '我的投票', icon: 'check-ticket', path: '/user/activity?title=我的投票' },
            { label: '我的订场', icon: 'sports-ground', path: '/user/activity?title=我的订场' },
          ],
        },
      ],
    };
  },
  computed: {
    ...mapGetters(['userId', 'nickname', 'deptName']),
  },
  methods: {
    logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$store.dispatch('LogOut').then(() => {
            location.href = '/home';
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: calc(100% - 30px);
  height: calc(100% - 110px);
  padding: 0 15px;

  ::v-deep .el-scrollbar {
    height: 100%;
  }

  .user-box {
    margin: 15px 0;
    display: flex;

    .avatar {
      width: 64px;
      height: 64px;
      margin: 0 20px;
      border-radius: 50%;
      background-color: #1477ff;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 22px;
      font-weight: bold;
      color: #fff;
    }

    .user-info {
      flex: 1;
      padding: 5px 0;
      // margin-left: 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .user-name {
        font-size: 20px;
        font-weight: bold;
      }

      .user-depart {
        font-size: 12px;
        color: #aab0ba;
      }
    }
  }

  .menu-box {
    padding: 15px;
    border-radius: 6px;
    background-color: #fff;
    margin-bottom: 15px;

    .menu-title {
      margin-bottom: 15px;
    }

    .content-box {
      display: flex;
      flex-wrap: wrap;
      // justify-content: space-between;

      .menu-item {
        width: 33.33%;
        text-align: center;
        cursor: pointer;
        // margin-right: calc((100% - 260px) / 2);
        padding: 15px 0;
        // margin-top: 10px;

        &:nth-child(3n) {
          margin-right: 0px;
        }

        &:nth-child(-n + 3) {
          margin-top: 0px;
        }

        .svg-icon {
          font-size: 32px;
          margin-bottom: 5px;
        }

        .label {
          font-size: 13px;
        }
      }
    }
  }
}
</style>
